//
//  firstViewController.m
//  ThreeFolks
//
//  Created by Pibinuo on 15/11/27.
//  Copyright © 2015年 皮比诺. All rights reserved.
//

#import "ScreenViewController.h"
#import "rootViewController.h"
#import "AppDelegate.h"
#import "LeftViewController.h"
#import "MBProgressHUD.h"
#import "AVOSCloud.h"
#import "LogRegisterHelper.h"
#import "RegisterViewController.h"
#import "currentState.h"





@interface ScreenViewController ()

@end

@interface ScreenViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIButton *denglu;
@property (weak, nonatomic) IBOutlet UIButton *resignin;
@property (weak, nonatomic) IBOutlet UIButton *youke;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *passwordLabel;
//宋
@property (weak, nonatomic) IBOutlet UITextField *nameTF;
@property (weak, nonatomic) IBOutlet UITextField *passwordTF;
@property(nonatomic,strong)MBProgressHUD *hud;




@end

@implementation ScreenViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"1.jpg"]];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
    [self setbutton];
    self.passwordTF.keyboardAppearance = UIKeyboardAppearanceDark;
    self.nameTF.keyboardAppearance = UIKeyboardAppearanceDark;
    [UIView animateWithDuration:1 delay:0 options:(UIViewAnimationOptionCurveEaseInOut) animations:^{
       
        self.nameTF.frame = CGRectMake(-200, 0, 0, 0);
        self.passwordTF.frame = CGRectMake(-200, 0, 0, 0);
        self.denglu.frame = CGRectMake(0, -600, 0, 0);
         self.resignin.frame = CGRectMake(0, -600, 0, 0);
        self.youke.frame = CGRectMake(0, -600, 0, 0);
        self.nameLabel.frame = CGRectMake(200, 0, 0, 0);
        self.passwordLabel.frame = CGRectMake(200, 0, 0, 0);
    } completion:nil];
}
// 回收键盘
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.nameTF resignFirstResponder];
    [self.passwordTF resignFirstResponder];
}


-(void)setbutton
{
    //    [self.denglu setImage:[UIImage imageNamed:@""] forState:(UIControlStateNormal)];
    //    self.denglu.layer.cornerRadius = 50;
    //    [self.resignin setImage:[UIImage imageNamed:@""] forState:(UIControlStateNormal)];
    //    self.resignin.layer.cornerRadius = 20;
    //    self.resignin.backgroundColor = [UIColor clearColor];
    //    [self.youke setImage:[UIImage imageNamed:@""] forState:(UIControlStateNormal)];
    
}

#pragma mark ---- song开始

- (IBAction)denglu:(id)sender {
    
    if (self.nameTF.text.length == 0) {
        [self showLetter:@"用户名不可以为空"];
    }else if (self.passwordTF.text.length == 0){
        [self showLetter:@"密码不能为空"];
    }else
    {
        [AVUser logInWithUsernameInBackground:self.nameTF.text password:self.passwordTF.text block:^(AVUser *user, NSError *error) {
            if (error == nil) {
                
                [self showLetter:@"登录成功"];
                [self.nameTF resignFirstResponder];
                [self.passwordTF resignFirstResponder];
                [currentState defaultState].isLoading = YES;
                [[LogRegisterHelper Share] Enter];
                
                
            }else if (error.code == 210){
                [self showLetter:@"密码错误重新输入"];
            }else if (error.code == 211){
                [self showLetter:@"该用户不存在"];
            }
            
        }];
    }

}

- (IBAction)signin:(id)sender {
    RegisterViewController * registerVC = [[RegisterViewController alloc] init];
    [self showViewController:registerVC sender:nil];
}
// MBP 展示的方法
- (void)showLetter:(NSString *)title
{
    self.hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    self.hud.mode = MBProgressHUDModeText;
    self.hud.labelText = title;
    [self.hud hide:YES afterDelay:2];
    
}

#pragma mark ----- song结束

- (IBAction)youke:(id)sender {
    AppDelegate * app = [UIApplication sharedApplication].delegate;
    [currentState defaultState].isLoading = NO;
    rootViewController * rootVC = [rootViewController new];
    LeftViewController * leftVC = [LeftViewController new];
    app.leftSlider = [[LeftSlideViewController alloc]initWithLeftView:leftVC andMainView:rootVC];
 
    app.window.rootViewController = app.leftSlider;
}









- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}





























@end
